package com.samphanie.auiu.common.http

import com.samphanie.auiu.common.utils.LocalCache
import com.samphanie.auiu.common.utils.SPUtil
import com.samphanie.auiu.library.restful.AuiuRestful

/**
 * @author Dries
 **/
object ApiFactory {

    private const val KEY_DEGRADE_HTTP = "degrade_http"
    private const val HTTPS_BASE_URL = "https://samphanie.vaiwan.com"

    private const val HTTP_BASE_URL = "http://samphanie.vaiwan.com"

    private val degrade2Http = SPUtil.getBoolean(KEY_DEGRADE_HTTP)
    private val baseUrl = if (degrade2Http) HTTP_BASE_URL else HTTPS_BASE_URL

    private val auiuRestful : AuiuRestful = AuiuRestful(baseUrl, RetrofitCallFactory(baseUrl))

    init {
        auiuRestful.addInterceptor(BizInterceptor())
        auiuRestful.addInterceptor(HttpStatusInterceptor())

        SPUtil.putBoolean(KEY_DEGRADE_HTTP, true)
    }

    fun <T> create(service: Class<T>): T {
        return auiuRestful.create(service)
    }
}